#include <QApplication>
#include "mainwindow.h"
#include <QFile>
#include <QtSvg>
#include "controller.h"
#include <QMetaType>
#include <QtXml>
#include <QDomDocument>
#include <QDomNode>
#include <QDomElement>
#include <QDebug>
#include "domnodelist.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTextCodec * codec = QTextCodec::codecForLocale();
    QTextCodec::setCodecForCStrings(codec);
    qRegisterMetaType< QVector<QStringList> >("QVector<QStringList>");
    MainWindow w;
    Controller c;

    QObject::connect(&w,SIGNAL(openFile(QString)),&c,SLOT(onOpenFile(QString)),Qt::QueuedConnection);
    QObject::connect(&w,SIGNAL(saveFile(QString,QVector<QStringList>)),&c,SLOT(onSaveFile(QString,QVector<QStringList>)),Qt::QueuedConnection);
    QObject::connect(&c,SIGNAL(sendShapes(QVector<QStringList>)),&w,SLOT(receiveShapes(QVector<QStringList>)),Qt::QueuedConnection);
    QObject::connect(&w, SIGNAL(shapeSelected(uint)),&c,SLOT(onShapeSelected(uint)),Qt::QueuedConnection);
    QObject::connect(&c,SIGNAL(redrawImage(QByteArray)),&w,SLOT(redraw(QByteArray)),Qt::QueuedConnection);
    QObject::connect(&w,SIGNAL(closeFile()),&c,SLOT(onCloseFile()),Qt::QueuedConnection);
    QObject::connect(&a,SIGNAL(lastWindowClosed()),&c,SLOT(quit()),Qt::QueuedConnection);
    c.start();
    w.show();
    if(argc>=2)
    {
        c.onOpenFile(QString(argv[1]));
    }
    int status = a.exec();
    while(!c.isFinished())
    {
    }
    return status;
}
